package net.roseparadise.config;

import java.util.Properties;

public class PropertiesConfig
{
    private Properties prop;

    private static PropertiesConfig instance;

    static
    {
        try
        {
            instance = new PropertiesConfig();
        }
        catch (Exception e) {}
    }

    public static PropertiesConfig getInstance()
    {
        return instance;
    }

    private PropertiesConfig() throws Exception
    {
        prop = new Properties();

        try{
            prop.load(getClass().getResourceAsStream("/net/roseparadise/config/prop.properties"));

		}catch (Exception e){
            System.out.println("illegal config environment because of " + e);
            throw new Exception(e.getMessage());
        }
    }

	public int getInt(String aKey)
	{
	    try{
	       return Integer.parseInt(prop.getProperty(aKey)!=null?((String)prop.getProperty(aKey)).trim():null);
  		}catch (Exception e){
  		   	throw new IllegalArgumentException("illegal int key: " + aKey);
  		}
  }

	public Object getObject(String aKey)
	{
	    try{
		    return prop.getProperty(aKey);
		}catch (Exception e){
		   	throw new IllegalArgumentException("illegal Object key: " + aKey);
		}
    }


    public String get(String aKey)
	{
	    return getString(aKey);
    }

    public String getString(String aKey)
	{
	    try {
		    return (String)prop.getProperty(aKey);
		}catch (Exception e){
		   	throw new IllegalArgumentException("illegal String key: " + aKey);
		}
    }

	public void setValue(String pName,String pValue)
	{
		prop.setProperty(pName,pValue);
	}
}